<template>
  <div>
    <MyHeader
      title="购物车案例"
      color="green"
      background="deepskyblue"
    ></MyHeader>
    <div class="main">
      <MyGoods :goodsObj="obj" v-for="obj in list" :key="obj.id"></MyGoods>
    </div>
    <MyFooter :list="list"></MyFooter>
  </div>
</template>

<script>
// 引入组件
import MyHeader from "@/components/ShoppingCart/MyHeader.vue";
import MyGoods from "@/components/ShoppingCart/MyGoods..vue";
import MyFooter from "@/components/ShoppingCart/MyFooter.vue";
export default {
  data() {
    return {
      list: [],
    };
  },
  //   注册组件
  components: {
    MyHeader,
    MyGoods,
    MyFooter,
  },
  created() {
    // 在该函数中发起网络请求
    this.$axios({
      url: "/api/cart",
    }).then((res) => {
      console.log(res);
      this.list = res.data.list;
    });
  },
};
</script>

<style scoped>
.main {
  padding: 50px 0 50px;
}
</style>